package com.bingwang.sourcelearn.transaction.tx01_jdbc.dao.impl;

import com.bingwang.sourcelearn.transaction.tx01_jdbc.dao.UserRepository;
import com.bingwang.sourcelearn.transaction.tx01_jdbc.model.UserPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @author WangBing
 * @date 2023/12/17 16:54
 */
@Repository
public class UserRepositoryImpl implements UserRepository {

    @Autowired
    JdbcTemplate jdbcTemplate;

    @Override
    public UserPO findById(Long id) {
        return jdbcTemplate.queryForObject("select id, name, age, sex from t_user where id = ?",
                new BeanPropertyRowMapper<>(UserPO.class), id);
    }
}
